package com.xyzwps.server.paimon.conf

import com.xyzwps.server.paimon.spring.customMethodArgumentResolvers
import com.xyzwps.server.paimon.ui.MvcAuthInterceptor
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.method.support.HandlerMethodArgumentResolver
import org.springframework.web.servlet.LocaleResolver
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor
import org.springframework.web.servlet.i18n.SessionLocaleResolver

@Configuration
class WebConfiguration : WebMvcConfigurer {

    @Autowired
    lateinit var mvcAuthInterceptor: MvcAuthInterceptor

    override fun addInterceptors(registry: InterceptorRegistry) {
        registry.addInterceptor(LocaleChangeInterceptor())
        registry.addInterceptor(mvcAuthInterceptor)
    }

    override fun addArgumentResolvers(resolvers: MutableList<HandlerMethodArgumentResolver>) {
        customMethodArgumentResolvers(resolvers)
    }

    @Bean
    fun localeResolver(): LocaleResolver {
        return SessionLocaleResolver()
    }
}